package workers

import (
	"cid-media-api/config"
	dataSyncDirectorMaterialAuditDataWorker "cid-media-api/workers/data/sync-director-material-audit-data"
	dataSyncEditorMaterialAuditDataWorker "cid-media-api/workers/data/sync-editor-material-audit-data"
	dataTiktokSyncEditorMaterialAuditDataWorker "cid-media-api/workers/data/tiktok-sync-editor-material-audit-data"
	dataTiktokUpdateHistoryEditorMaterialAuditDataWorker "cid-media-api/workers/data/tiktok-update-history-editor-material-audit-data"
	dataUpdateHistoryDirectorMaterialAuditDataWorker "cid-media-api/workers/data/update-history-director-material-audit-data"
	dataUpdateHistoryEditorMaterialAuditDataWorker "cid-media-api/workers/data/update-history-editor-material-audit-data"
	oceanQCGetAdvertiserReportDayJlnWorker "cid-media-api/workers/ocean-qc/get-advertiser-report/jln"
	oceanQCGetMaterialReportDayJlnWorker "cid-media-api/workers/ocean-qc/get-material-report-day/jln"
	oceanGetAdvertiserReportDayJlnWorker "cid-media-api/workers/ocean/get-advertiser-report/jln"
	oceanGetMaterialReportDayJlnWorker "cid-media-api/workers/ocean/get-material-report-day/jln"
	"log"
)

func SetupWorkers() {

	//oceanGetAdvertiserFundWorker.Run()
	//oceanGetAdvertiserFundDailyStatWorker.Run()
	//oceanGetAdvertiserReportDayWorker.Run()

	tasks := config.AppConfig.CronJob.Tasks

	// 定义一个映射，将任务名称映射到相应的函数
	var workerMap = map[string]func(cron string){
		"get-advertiser-report-day-jln":                    oceanGetAdvertiserReportDayJlnWorker.Run,
		"get-material-report-day-jln":                      oceanGetMaterialReportDayJlnWorker.Run,
		"sync-editor-material-audit-data":                  dataSyncEditorMaterialAuditDataWorker.Run,
		"sync-director-material-audit-data":                dataSyncDirectorMaterialAuditDataWorker.Run,
		"update-history-editor-material-audit-data":        dataUpdateHistoryEditorMaterialAuditDataWorker.Run,
		"update-history-director-material-audit-data":      dataUpdateHistoryDirectorMaterialAuditDataWorker.Run,
		"get-qc-advertiser-report-day-jln":                 oceanQCGetAdvertiserReportDayJlnWorker.Run,
		"get-qc-material-report-day-jln":                   oceanQCGetMaterialReportDayJlnWorker.Run,
		"tiktok-sync-editor-material-audit-data":           dataTiktokSyncEditorMaterialAuditDataWorker.Run,
		"tiktok-update-history-editor-material-audit-data": dataTiktokUpdateHistoryEditorMaterialAuditDataWorker.Run,
	}

	for _, task := range tasks {
		if workerFunc, exists := workerMap[task.Name]; exists {
			if task.Enable {
				log.Printf("启动定时任务 %s (%s)", task.Name, task.Note)
				go func(cronSpec string) {
					workerFunc(cronSpec)
				}(task.CronSpec)
			}
		}
	}

}
